<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 200px;
            height: 200px;
            position: absolute;
            top: 500px;
            left: 0px;
            background: url("image/konglong.jpg");
            background-size: 200px 200px;
            /* transition: all 2s; */
            /* animation: aoo 4s; */
            
        }
        @keyframes aoo{
            0%{
                top:500px;
                left: 0;
            }
            50%{
                top:300px;
                left:100px;
            }
            100%{
                top:500px;
                left: 160px;
            }
        }
        @keyframes ddd{
            0%{
                top:500px;
                left: 160px;
            }
            50%{
                top:100px;   
                left:260px;
            }
            100%{
                top:500px;
                left: 320px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        var box=document.querySelector(".box");
        var cc=document.styleSheets[0];
        console.log(cc);
        var a=0;
        document.onkeyup=function(e){
            console.log(e.keyCode);
            
            if (a==0 && e.keyCode==32) {
                a++;
                box.style.animation=" aoo 4s";
                box.style.animationFillMode= "forwards";
            }else{
                a--;
                box.style.animation=" ddd 4s";
                box.style.animationFillMode= "forwards";
            }
        }
        
    </script>
</body>
</html>